<template>
  <el-row type="flex" justify="space-between" align="middle" style="width:100%;height: 40px">
    <el-col>
      <strong v-if="isBold"><i class="el-icon-s-home" /> {{ treeNode.name }}</strong>
      <span v-else>{{ treeNode.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ treeNode.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown>
            <span>
              操作<i class="el-icon-arrow-down" />
            </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="addDepartment">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isBold" @click.native="editdepartment">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isBold" @click.native="deleteDepartment">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { deleteDepartment } from '@/api/departments'
export default {
  props: {
    treeNode: {
      type: Object,
      required: true
    },
    isBold: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    async deleteDepartment() {
      try {
        await this.$confirm('是否确认删除？')
        await deleteDepartment(this.treeNode.id)
        this.$message.success('删除成功')
        this.$emit('delDepartment')
      } catch (error) {
        console.log(error)
      }
    },
    // 添加部门处理函数
    addDepartment() {
      // 把当前点击的对象传递给父组件，让父组件做添加部门处理
      console.log(this.treeNode)
      this.$emit('addDepartment', this.treeNode)
    },
    // 编辑部门处理函数
    editdepartment() {
      // 把treeNode对象传递给父组件，让父组件做处理
      this.$emit('editdepartment', this.treeNode)
    }
  }
}
</script>

<style>

</style>
